import icons from '../images/chartImages';
import { Ajax } from '../utils/http';

export class StaticticService {
    private symbol: string;
    constructor(_symbol: string) {
        this.symbol = _symbol;
    }

    public async send(): Promise<StatisticResponse> {
        var response: StatisticResponse;
        var data = {
            symbol: this.symbol,
        }
        try {
            response = await new Ajax<StatisticResponse>('/oliview_data', data,true).get();
        } catch (e) {
            throw e;
        }
        return response;
    }
}

/*Summary*/
export interface Summary {
    symbol: string;
    name: string;
    date: number;
}

/*Incomes*/
export interface Incomes {
    symbol: string;
    name: string;
    date: number;
    gross_margin: number;
    operating_margin: number;
    net_profit_margin: number;
    return_on_investment: number;
    financial_years: Array<string>;
    total_revenues: Array<number>;
    net_incomes: Array<number>;
}

/*Assets*/
export interface Assets {
    symbol: string;
    name: string;
    date: number;
    quick_ratio: number;
    current_ratio: number;
    long_term_debt_to_equity: number;
    total_debt_to_equity: number;
    financial_years: Array<string>;
    total_assets: Array<number>;
    total_liabs: Array<number>;
}

/*Cash flows*/
export interface CashFlows {
    symbol: string;
    name: string;
    date: number;
    revenue_per_common_share: number;
    operating_cash_flow: number;
    financial_years: Array<string>;
    cashes: Array<number>;
    change_in_cashes: Array<number>;
}

/*Latest_recommendations*/
export interface LatestRecommendations {
    date: string;
    analyst: string;
    rating: number;
    target_price: number;
    firm_name: string;
}



/*Finances*/
export interface Finances {
    incomes: Incomes;
    assets: Assets;
    cash_flows: CashFlows;
}

/*tsModel6*/
export interface StatisticResponse {
    summary: Summary;
    finances: Finances;
    latest_recommendations: LatestRecommendations[];
    strategies: Array<Strategies>;
}


export interface Strategies {
    strategy_name: string;
    begin_date: string;
    end_date: string;
    strategy_results: Array<any>
}

export interface StrategyLine {
    strategy_name: string;
    strategies:Array<Strategies>;
}

export enum StatisticType {
    incomes = 0,
    assets = 1,
    cashFlows = 2
}
export const StrategiesMap: any = {
    "sym_triangle_strategy": { icon: icons.sym_triangle_strategy, name: '对称三角形' },
    "ascending_triangle_strategy": { icon: icons.ascending_triangle_strategy, name: '上升三角形' },
    "descending_triangle_strategy": { icon: icons.descending_triangle_strategy, name: '下降三角形' },
    "flags_strategy": { icon: icons.flags_strategy, name: '通道' },
    "engulfing_pattern": { icon: icons.flags_strategy, name: '吞噬模式' },
    "shooting_star": { icon: icons.flags_strategy, name: '射击之星' },
    "hanging_man": { icon: icons.flags_strategy, name: '上吊线' },
    "inverted_hammer": { icon: icons.flags_strategy, name: '倒锤头' },
    "evening_star": { icon: icons.evening_star, name: '暮星' },
    "hammer": { icon: icons.flags_strategy, name: '锤头' },
    "dark_cloud_cover": { icon: icons.flags_strategy, name: '乌云压顶' },
    "morning_star": { icon: icons.morning_star, name: '晨星' },
    "three_black_crows": { icon: icons.three_black_crow, name: '三只乌鸦' },
    "three_advancing_white_soldiers": { icon: icons.three_white_soldiers, name: '白色三兵' },
}

export const StrategyLineList: string[] = ['sym_triangle_strategy', 'ascending_triangle_strategy', 'descending_triangle_strategy', 'flags_strategy'];